// pages/goupiao/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: [1, 2, 3, 45],
    bannerIndex: 1,
    bannerType: 0,
    dateList: [],
    dateIndex: 0,
    weekName: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
    timeList: ['09:00-12:00', '12:00-18:00', '09:00-12:00'],
    timeIndex: 0,
  },
  // 选中场次
  choiceDate(e) {
    console.log(e)
    const {
      dateindex,
      timeindex
    } = e.currentTarget.dataset
    this.setData({
      dateIndex: dateindex,
      timeIndex: timeindex
    })
  },
  // 立即支付
  confirm() {
    wx.navigateTo({
      url: '/pages/zuqiu/shiming/index',
    })
  },
  // 轮播图切换事件
  swiperChange(e) {
    this.setData({
      bannerIndex: e.detail.current + 1
    })
  },
  // 切换出行日期
  setdate(e) {
    console.log(e)
    const {
      key,
      value
    } = e.currentTarget.dataset
    this.setData({
      [key]: value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  getStartTime(time) {
    const nowTimeDate = new Date(time)
    return nowTimeDate.setHours(0, 0, 0, 0)
  },
  // 时间戳转日期格式
  timestampToTime(timestamp) {
    var date = new Date(timestamp)
    var Y = date.getFullYear() + '.'
    var M =
      (date.getMonth() + 1 < 10 ?
        '0' + (date.getMonth() + 1) :
        date.getMonth() + 1) + '.'
    var D = date.getDate()
    return Y + M + D
  },
  getWeek(time, index) {
    let week = this.data.weekName[new Date(time).getDay()]
    let daysName = ['今天', '明天', '后天']
    if (index < daysName.length) {
      week = daysName[index]
    }
    return week
  },
  // 获取一周的日期
  getWeekList(type) {
    let week = []
    let today = this.getStartTime(Number(new Date())) // 当天时间戳
    for (var i = 0; i < 4; i++) {
      let weekObj = {
        name: this.getWeek(today + i * 1000 * 60 * 60 * 24, i),
        date: '',
        timeStamp: today + i * 1000 * 60 * 60 * 24,
      }
      week.push(weekObj)
    }
    week.map((el) => {
      el.date = this.timestampToTime(el.timeStamp)
    })
    const dateList = JSON.parse(JSON.stringify(week))
    this.setData({
      dateList
    })
  },
  onLoad(options) {
    this.getWeekList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})